<?php
namespace app\api\controller;
use app\common\BaseController;
use think\Db;
class TeamSummary extends BaseController{
    public function __construct(){
        parent::__construct();        
    }
    
    public function index(){  
        $params = $this->request->param();   
        $where=[];
        if(isset($params['job_no'])){
            $where['operator_no']=$params['job_no'];
        }
        $sub=Db::table('lt_insure_team')  
        ->field("*,count(*) as num,sum(premium) as total") 
        ->where($where)
        ->where('start_date','between time',[$params['start_date'],$params['end_date']])
        ->group('product_name')        
        ->buildSql();
        $data=Db::table("{$sub} a")  
        ->field("a.*,b.*,total*(b.rate/100) as fee")      
        ->join("lt_insure b","a.product_name=b.insure_name")
        ->select();
        return $data;
    }
}